import { Window } from "../../../../component/window/Window";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../../resource/ImagesConst";
import { ObjCreate } from "../../common/ObjCreate";
import { GImageBitmap } from "../../../../../com/mui/controls/GImageBitmap";
import { PetItem } from "../PetItem";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { Language } from "../../../../../extend/language/Language";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { SPetInfo } from "../../../../../Message/Game/SPetInfo";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { PetIlluEventName } from "./PetIlluEventName";
import { Global } from "../../../../../com/gengine/global/Global";
import { SWFPlayer } from "../../../scene/modle/SWFPlayer";
import { ModelType } from "../../../scene/modle/data/ModelType";
type int = number;
//class PetIlluNewWindow
    
    export  class PetIlluNewWindow extends Window
    {
        constructor()
        {
            super();
            setSize(610, 105);
            this.buttonMode = true;
            this.useHandCursor = true;
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onClickHandler);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            _windowBg = ResouceConst.getScaleBitmap(ImagesConst.PetIlluNewBg);
            _windowBg.width = 610;
            _windowBg.height = 105;
            $addChildAt(_windowBg, 0);
            ObjCreate.createBg(20, 15, 568, 75, this);
            this.addChild(new GImageBitmap(ImagesConst.PetNameBg, 30, 20));
            this._petItem = new PetItem();
            this._petItem.setSize(48, 48);
            this._petItem.move(48, 25);
            this._petItem.mouseEnabled = false;
            this.addChild(this._petItem);
            this._nameTxt = ObjCreate.createTextField("", 115, 47, 115, 20, this, GlobalStyle.textFormat8);
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._nameTxt.mouseEnabled = false;
            ObjCreate.createTextField(Language.getString(54079), 285, 20, 280, 25, this, new GTextFormat(FontUtil.songtiName, 16, 15788607));
            this._tipTxt = ObjCreate.createTextField("", 285, 45, 280, 25, this);
            this._tipTxt.mouseEnabled = false;
            this._tipTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._tipTxt.multiline = true;
            this._tipTxt.wordWrap = true;
            this._tipTxt.htmlText = "<textFormat leading=\'5\'>" + Language.getString(54080) + "</textFormat>";
            return;
        }

        public updateByPet(arg1: SPetInfo): void
        {
            this._petInfo = arg1;
            if (arg1) 
            {
                this._nameTxt.text = arg1.name;
                this._petItem.dragSource = arg1;
            }
            return;
        }

        protected /* override */ updateBtnSize(): void
        {
            super.updateBtnSize();
            _closeBtn.x = this.width - _closeBtn.width - 5;
            _closeBtn.y = 7;
            return;
        }

        /* internal  */onClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (arg1.target as GButton == null) 
            {
                if (this._petInfo) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(PetIlluEventName.GotoPetPageIndex, this._petInfo.code));
                }
            }
            this.hide();
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            arg1 = (Global.stage.stageWidth - this.width) / 2;
            arg2 = Global.stage.stageHeight - this.height - 100;
            super.show(arg1, arg2);
            if (this.hideTimer == null) 
            {
                this.hideTimer = new Object /* flash.utils.Timer */(1000);
                this.hideTimer.repeatCount = 5;
                this.hideTimer.addEventListener(flash.events.TimerEvent.TIMER_COMPLETE, this.onTimerCompleteHandler);
            }
            this.hideTimer.reset();
            this.hideTimer.start();
            this.playEffect();
            return;
        }

        /* internal  */playEffect(): void
        {
            if (this._effectPlayer == null) 
            {
                this._effectPlayer = new SWFPlayer();
            }
            this._effectPlayer.load("PetIlluNew.swf", ModelType.NormalSwf, null);
            this._effectPlayer.move(280, 130);
            if (this.contains(this._effectPlayer) == false) 
            {
                this.addChild(this._effectPlayer);
            }
            return;
        }

        /* internal  */onTimerCompleteHandler(arg1: Object /* flash.events.Event */): void
        {
            this.hideTimer.stop();
            this.hide();
            return;
        }

        /* internal */ /* var */_effectPlayer: SWFPlayer;

        /* internal */ /* var */_petItem: PetItem;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_tipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_petInfo: SPetInfo;

        /* internal */ /* var */hideTimer: Object /* flash.utils.Timer */;
    }
